/************************************************************************
 * <br>
 * <ul>
 * <li>版权所有：唐山弘川科技有限公司 2009－2020</li>
 * <li>创建日期：2009-8-7</li>
 * <li>初始作者：刘川</li>
 * </ul>
 * <ul>
 * <b>修订历史</b>
 * <li>1、</li>
 * </ul>
 ***********************************************************************/
package com.hy.enterprise.framework.persistence.entity ;

import java.io.Serializable ;

import javax.persistence.Column ;
import javax.persistence.Id ;
import javax.persistence.MappedSuperclass ;

import org.apache.commons.lang.builder.CompareToBuilder ;
import org.apache.commons.lang.builder.EqualsBuilder ;
import org.apache.commons.lang.builder.HashCodeBuilder ;
import org.apache.commons.lang.builder.ToStringBuilder ;
import org.apache.commons.lang.builder.ToStringStyle ;
import org.hibernate.annotations.Index ;

import com.extjs.gxt.ui.client.data.BaseModel ;
import com.hy.mydesktop.shared.persistence.domain.util.Persistable;

/**
 * <ul>
 * <li>设计作者：刘川</li>
 * <li>设计日期：2009-8-7</li>
 * <li>设计时间：下午08:59:43</li>
 * <li>设计目的：持久化数据模型抽象实现类</li>
 * </ul>
 * <ul>
 * <b>修订历史</b>
 * <li>1、</li>
 * </ul>
 */
@ SuppressWarnings ( "unchecked" )
@ MappedSuperclass
public class AbstractPersistentEntity  extends BaseModel implements Persistable , Comparable ,
        Cloneable , Serializable
{
	private static final long	serialVersionUID	=
	                                                  7750384559204769902L ;

	/**
	 * 乐观锁版本字段
	 */
	private Integer	          entityVersion ;

	/**
	 * 持久化标识符
	 */
	private String	          identifier ;
	private String	          id ;

	/**
	 * 构造函数
	 */
	public AbstractPersistentEntity ( )
	{
		super ( ) ;
	}

	/**
	 * 构造函数
	 * 
	 * @param identifier
	 */
	public AbstractPersistentEntity (
	                                  String identifier )
	{
		super ( ) ;
		this.identifier =
		                  identifier ;
	}

	/**
	 * @see java.lang.Object#clone()
	 */
	@ Override
	protected Object clone ( )
	                          throws CloneNotSupportedException
	{
		AbstractPersistentEntity clone =
		                                 AbstractPersistentEntity.class
		                                                               .cast ( super
		                                                                            .clone ( ) ) ;
		clone.identifier =
		                   null ;
		return clone ;
	}

	/**
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@ Override
	public int compareTo (
	                       Object other )
	{
		return CompareToBuilder
		                       .reflectionCompare (
		                                            this ,
		                                            other ) ;
	}

	@ Override
	public boolean equals (
	                        Object other )
	{
		if ( null == other )
		{
			return false ;
		}
		else
		{
			return EqualsBuilder
			                    .reflectionEquals (
			                                        this ,
			                                        other ) ;
		}
	}

	/**
	 * <ul>
	 * <li>设计作者：刘川</li>
	 * <li>设计日期：2009-8-14</li>
	 * <li>设计时间：下午04:04:48</li>
	 * <li>设计目的：获取乐观锁版本字段</li>
	 * </ul>
	 * <ul>
	 * <b>修订历史</b>
	 * <li>1、</li>
	 * </ul>
	 * 
	 * @return
	 */
	public Integer getEntityVersion ( )
	{
		return this.entityVersion ;
	}

	/**
	 * @see com.hy.mydesktop.shared.persistence.domain.util.Identifierable#getIdentifier()
	 */
	@ Id
	@ Column ( name = "identifier" , length = 36 , unique = true , nullable = false )
	@ Index ( name = "identifierIndex" )
	@ Override
	public String getIdentifier ( )
	{
		return this.identifier ;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@ Override
	public int hashCode ( )
	{
		return HashCodeBuilder
		                      .reflectionHashCode ( this ) ;
	}

	/**
	 * <ul>
	 * <li>设计作者：刘川</li>
	 * <li>设计日期：2009-8-14</li>
	 * <li>设计时间：下午04:04:05</li>
	 * <li>设计目的：设置乐观锁版本字段</li>
	 * </ul>
	 * <ul>
	 * <b>修订历史</b>
	 * <li>1、</li>
	 * </ul>
	 * 
	 * @param entityVersion
	 */
	public void setEntityVersion (
	                               Integer entityVersion )
	{
		this.entityVersion =
		                     entityVersion ;
	}

	/**
	 * @see com.hy.mydesktop.shared.persistence.domain.util.Identifierable#setIdentifier(java.io.Serializable)
	 */
	@ Override
	public void setIdentifier (
	                            String identifier )
	{
		this.identifier =
		                  identifier ;
		this.id=identifier;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@ Override
	public String toString ( )
	{
		return ToStringBuilder
		                      .reflectionToString (
		                                            this ,
		                                            ToStringStyle.MULTI_LINE_STYLE ) ;
	}

	@Override
	public String getId() {
		// TODO Auto-generated method stub
		return id;
	}

	@Override
	public void setId(String id) {
		this.id=id;
		this.identifier=id;
		
	}

	
	
}
